/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import model.Usuario;
import model.Viaje;
import java.util.List;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import service.UsuarioService;
import service.LugarService;

/**
 *
 * @author MIS DOCUMENTOS
 */
public class CrearViajeIndex extends AbstractCommandController {

    private UsuarioService usuarioService;
    private LugarService lugarService;
    private static Logger loggers = null;

    public void setUsuarioService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

    public void setLugarService(LugarService lugarService) {
        this.lugarService = lugarService;
    }

    public CrearViajeIndex() {
        this.setCommandClass(Usuario.class);
        loggers = Logger.getLogger(Usuario.class.getName());
        loggers.setLevel(Level.ALL);
        DOMConfigurator.configure("C:/Documents and Settings/Administrador/Escritorio/HayTour - Repositorio/hayTourViajes/src/java/main/resources/log4j.xml");

    }

    @Override
    protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object form, BindException errors) throws Exception {
        Map model = new HashMap();

        Usuario user2;
        user2 = (Usuario) usuarioService.getUsuario(Long.parseLong(request.getParameter("ux")));
        List lugares;

        lugares = lugarService.getPaisList();

        request.getSession().setAttribute("usuarioList", null);
        model.put("usuario", user2);
        model.put("lugar", lugares);
        return new ModelAndView("crearViaje", model);

    }
}
